home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / internet / other / ka9q / ka9q_src.arc / AX25USER.C < prev    next >
Encoding:
C/C++ Source or Header  |  1988-11-29  |  2.7 KB  |  125 lines

  1. /* User subroutines for AX.25 */
  2. #include "global.h"
  3. #include "mbuf.h"
  4. #include "timer.h"
  5. #include "iface.h"
  6. #include "ax25.h"
  7. #include "lapb.h"
  8. #include <ctype.h>
  9.  
  10. /* Open an AX.25 connection */
  11. struct ax25_cb *
  12. open_ax25(addr,window,r_upcall,t_upcall,s_upcall,iface,user)
  13. struct ax25 *addr;        /* Addresses */
  14. int16 window;            /* Window size in bytes */
  15. void (*r_upcall)();        /* Receiver upcall handler */
  16. void (*t_upcall)();        /* Transmitter upcall handler */
  17. void (*s_upcall)();        /* State-change upcall handler */
  18. struct interface *iface;    /* Hardware interface structure */
  19. char *user;            /* User linkage area */
  20. {
  21.     struct ax25_cb *axp,*cr_ax25();
  22.  
  23.     if((axp = cr_ax25(&addr->dest)) == NULLAX25)
  24.         return NULLAX25;
  25.     ASSIGN(axp->addr,*addr);
  26.     if(addr->ndigis != 0){
  27.         axp->t1.start *= (addr->ndigis + 1);
  28.         axp->t2.start *= (addr->ndigis + 1);
  29.         axp->t3.start *= (addr->ndigis + 1);
  30.     }
  31.     axp->window = window;
  32.     axp->r_upcall = r_upcall;
  33.     axp->t_upcall = t_upcall;
  34.     axp->s_upcall = s_upcall;
  35.     axp->interface = iface;
  36.     axp->user = user;
  37.  
  38.     if(axp->state == DISCONNECTED){
  39.         /* Don't send anything if the connection already exists */
  40.         lapbstate(axp,SETUP);
  41.         sendctl(axp,COMMAND,SABM|PF);
  42.     }
  43.     return axp;
  44. }
  45.  
  46. /* Send data on an AX.25 connection. Caller must provide PID */
  47. send_ax25(axp,bp)
  48. struct ax25_cb *axp;
  49. struct mbuf *bp;
  50. {
  51.     if(axp == NULLAX25 || bp == NULLBUF)
  52.         return;
  53.     enqueue(&axp->txq,bp);
  54.     lapb_output(axp);
  55. }
  56.  
  57. /* Receive incoming data on an AX.25 connection */
  58. struct mbuf *
  59. recv_ax25(axp,cnt)
  60. register struct ax25_cb *axp;
  61. int16 cnt;
  62. {
  63.     struct mbuf *bp;
  64.  
  65.     if(axp->rxq == NULLBUF)
  66.         return NULLBUF;
  67.  
  68.     bp = axp->rxq;
  69.     axp->rxq = NULLBUF;
  70.  
  71.     /* If this has un-busied us, send a RR to reopen the window */
  72.     if(len_mbuf(bp) >= axp->window)
  73.         sendctl(axp,RESPONSE,RR);
  74.     return bp;
  75. }
  76.  
  77. /* Close an AX.25 connection */
  78. disc_ax25(axp)
  79. struct ax25_cb *axp;
  80. {
  81.     if(axp->state == DISCPENDING){
  82.         lapbstate(axp,DISCONNECTED);
  83.         del_ax25(axp);
  84.     } else {
  85.         lapbstate(axp,DISCPENDING);
  86.         sendctl(axp,COMMAND,DISC|PF);
  87.     }
  88. }
  89.  
  90. /* Verify that axp points to a valid ax25 control block */
  91. ax25val(axp)
  92. struct ax25_cb *axp;
  93. {
  94.     register struct ax25_cb *axp1;
  95.     register int i;
  96.  
  97.     if(axp == NULLAX25)
  98.         return 0;    /* Null pointer can't be valid */
  99.     for(i=0; i < NHASH; i++)
  100.         for(axp1 = ax25_cb[i];axp1 != NULLAX25; axp1 = axp1->next)
  101.             if(axp1 == axp)
  102.                 return 1;
  103.     return 0;
  104. }
  105.  
  106. /* Force a retransmission */
  107. kick_ax25(axp)
  108. struct ax25_cb *axp;
  109. {
  110.     void recover();
  111.  
  112.     if(!ax25val(axp))
  113.         return -1;
  114.     recover((int *)axp);
  115.     return 0;
  116. }
  117.  
  118. /* Abruptly terminate an AX.25 connection */
  119. reset_ax25(axp)
  120. struct ax25_cb *axp;
  121. {
  122.     lapbstate(axp,DISCONNECTED);
  123.     del_ax25(axp);
  124. }
  125.